﻿using System;
using System.Collections.Generic;
using System.Text;
using System.Data;
using System.IO;

namespace DrugStorehouseMIS.Comm
{
    public class EventLog
    {
        public EventLog()
        {
              
        }

        public static void WriteErrorLog(string ErrorText)
        {
            string FolderPath = AppDomain.CurrentDomain.BaseDirectory + @"\EventLog";
            string FilePath = AppDomain.CurrentDomain.BaseDirectory + @"\EventLog\" + DateTime.Today.ToString("dd-mm-yy") + ".txt";
            if (!Directory.Exists(FolderPath))
            {
                Directory.CreateDirectory(FolderPath);
            }

            if (!File.Exists(FilePath))
            {
                FileStream fs;
                fs=File.Create(FilePath);
                fs.Close();
            }
            using (StreamWriter writer = File.AppendText(FilePath))
            {
                writer.WriteLine("Log Entry : ");
                writer.WriteLine("{0}", DateTime.Now.ToString());
                string err = "Error Message:" + ErrorText;
                writer.WriteLine(err);
                writer.WriteLine("_________________________________");
                writer.Flush();
                writer.Close();
            }          
        }
    }
}
